<?php

namespace app\manage\middleware;

use Closure;
use think\facade\Config;
use think\Request;
use think\Response;

class CheckLogin
{
    /**
     * 处理请求
     *
     * @param Request $request
     * @param Closure $next
     * @return Response
     */
    public function handle(Request $request, Closure $next): Response
    {
        $header = $request->header();
        if(!empty($header['e-token'])){
            $res = checkToken($header['e-token'],Config::get('jwt.key'));
            if(!isset($res['status'])){
                return jsonR($res);
            }
            $request->uid = $res['data']->uid;
        }else{
            return jsonR('login error,token missing!');
        }
        return $next($request);
    }
}
